home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / nurbsViewDirectionVector.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  3.3 KB  |  117 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17.  
  18. //
  19. // Alias|Wavefront Script File
  20. // MODIFY THIS AT YOUR OWN RISK
  21. //
  22. // Creation Date: April 15 1998.
  23. //  Author: rs 
  24. //
  25. //  Description:
  26. //  This script returns the active camera view direction as a float[].  The
  27. //  vector is normalized.
  28. //
  29.  
  30. global proc float[] nurbsViewDirectionVector( int $onlyOrtho )
  31. //
  32. //  Description :
  33. //      Get the current camera view direction as a normalized vector.
  34. //      If $onlyOrtho flag is set to true, this is done for the orthogonal
  35. //      cameras only; the perspective cameras get the default up direction
  36. //      returned as the result.
  37. //
  38. {
  39.     float $result[];
  40.  
  41.     string $isitYup = `upAxis -q -ax`;
  42.     if( "y" == $isitYup ) {
  43.         $result[0] = 0.0 ;
  44.         $result[1] = 1.0 ;
  45.         $result[2] = 0.0 ;
  46.     }
  47.     else {
  48.         $result[0] = 0.0 ;
  49.         $result[1] = 0.0 ;
  50.         $result[2] = 1.0 ;
  51.     }
  52.  
  53.     string $forTheWarning = "Failed to compute active camera view direction." +
  54.                             "  Using the default (" + $result[0] + "," +
  55.                             $result[1] + "," + $result[2] + ")";
  56.  
  57.     // get the current camera view.
  58.     //
  59.     string $cameraName ;
  60.     if( catch( $cameraName = `lookThru -q` ) ) {
  61.         warning $forTheWarning;
  62.         return $result ;
  63.     }
  64.  
  65.     if( $onlyOrtho && !`camera -q -o $cameraName` ) {
  66.         // Don't do anything for perspective cameras...
  67.         return $result;
  68.     }
  69.  
  70.     float $coiDistance = 0.0 ;
  71.     if( catch( $coiDistance = `camera -q -coi $cameraName` )) {
  72.         warning $forTheWarning;
  73.         return $result ;
  74.     }
  75.  
  76.     // save the selection list because createNode changes it.
  77.     // Later, we need this to restore the selection list.
  78.     string $selectionList[] = `ls -sl`;
  79.  
  80.     string $ppm ;
  81.     if( catch($ppm = `createNode pointMatrixMult`) ) {
  82.         warning $forTheWarning;
  83.         select -r $selectionList;
  84.         return $result ;
  85.     }
  86.  
  87.     // restore the selection list
  88.     //
  89.     select -r $selectionList;
  90.  
  91.     // compute the view direction.
  92.     //
  93.     setAttr ($ppm +".inPoint") -type double3 0.0 0.0 (-$coiDistance) ;
  94.     setAttr ($ppm +".vectorMultiply") true ;
  95.     connectAttr ($cameraName+".worldMatrix[0]") ($ppm+".inMatrix") ;
  96.     float $coi[] = `getAttr ($ppm+".output")` ;
  97.     delete $ppm ;
  98.  
  99.     // fill up the result.
  100.     //
  101.     int $i ;
  102.     float $sum = 0;
  103.     for( $i = 0 ; $i < 3 ; $i++ ) {
  104.         $sum += ($coi[$i] * $coi[$i]);
  105.         $result[$i] = $coi[$i];
  106.     }
  107.  
  108.     if( $sum > 0 ) {
  109.         $sum = -1.0/sqrt($sum);
  110.         for( $i = 0 ; $i < 3 ; $i++ ) {
  111.             $result[$i] = $result[$i] * $sum;
  112.         }
  113.     }
  114.     return $result ;
  115. }
  116.  
  117.